<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: TypoPermalinkWithId::ModifyArticlesController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">TypoPermalinkWithId::ModifyArticlesController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/typo_permalink_with_id_rb.html">
                lib/typo_permalink_with_id.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
When <a href="ModifyArticlesController.html#M000001">included</a> modifies
how permalink finds an article
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000001">included</a>&nbsp;&nbsp;
      <a href="#M000002">modified_permalink</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000001" class="method-detail">
        <a name="M000001"></a>

        <div class="method-heading">
          <a href="#M000001" class="method-signature">
          <span class="method-name">included</span><span class="method-args">(base)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Alias the original method, permalink, to the new <a
href="ModifyArticlesController.html#M000002">modified_permalink</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000001-source">
<pre>
    <span class="ruby-comment cmt"># File lib/typo_permalink_with_id.rb, line 17</span>
17:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">included</span>(<span class="ruby-identifier">base</span>)
18:       <span class="ruby-identifier">base</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
19:         <span class="ruby-identifier">alias_method</span> <span class="ruby-identifier">:permalink</span>, <span class="ruby-identifier">:modified_permalink</span>
20:       <span class="ruby-keyword kw">end</span>
21:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000002" class="method-detail">
        <a name="M000002"></a>

        <div class="method-heading">
          <a href="#M000002" class="method-signature">
          <span class="method-name">modified_permalink</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
First try to find the article as usual, by full permalink, since that will
find both articles in the new scheme, and links to articles in the old
scheme. Then if not found try to find by id and redirect to the correct
permalink. If that doesn&#8216;t work, it is probably an old link to an
updated article, so search by the title without the prefix. If all else
fails, the display_article call with null will show the default Typo
&quot;post not found&quot; error, as before.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000002-source">
<pre>
    <span class="ruby-comment cmt"># File lib/typo_permalink_with_id.rb, line 27</span>
27:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">modified_permalink</span>
28:       <span class="ruby-identifier">article</span> = <span class="ruby-identifier">this_blog</span>.<span class="ruby-identifier">published_articles</span>.<span class="ruby-identifier">find_by_permalink</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">params</span>.<span class="ruby-identifier">values_at</span>(<span class="ruby-identifier">:year</span>, <span class="ruby-identifier">:month</span>, <span class="ruby-identifier">:day</span>, <span class="ruby-identifier">:title</span>))
29:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">article</span>.<span class="ruby-identifier">permalink_url</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">article</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">article</span> = <span class="ruby-constant">Article</span>.<span class="ruby-identifier">find_by_id</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:title</span>].<span class="ruby-identifier">to_i</span>)
30:       <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">article</span>.<span class="ruby-identifier">permalink_url</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">article</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">article</span> = <span class="ruby-constant">Article</span>.<span class="ruby-identifier">find_by_title</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:title</span>])
31:       <span class="ruby-identifier">display_article</span>(<span class="ruby-identifier">article</span>)
32:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>